<script>
function genTree(arr){
    function tree(id){
        let data = []
        let children = arr.filter(item => item.parent_id === id)
        children.forEach(item => {
            data.push({
                id: item.id,
                name: item.name,
                children: tree(item.id)
            })
        })
        return data
    }
    return tree('')[0]
}


</script>